﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CH03_09
{
    class CH03_09
    {
        private static int iStudents;

        static void Main(string[] args)
        {
            /*
             * 参数含义:
             * nStudents:用于统计学生人数;
             * tempScore:接收每次输入的成绩;
             * maxScore,minScore:成绩最大值、成绩最小值;
             */
            int nStudents;
            int tempScore;
            int maxScore = 0, minScore = 0;
            int score0To59 = 0, score60To69 = 0, score70To79 = 0, score80To89 = 0, score90To100 = 0;

            Console.WriteLine("--------学生成绩统计--------");
            Console.WriteLine("请输入班级人数:nStudents = ");

            string s = Console.ReadLine();
            nStudents = Int32.Parse(s);

            // 接收并处理学生成绩;
            for(int i = 1; i <= nStudents; i++)
            {
                Console.WriteLine("请输入第{0:d}个学生的成绩", i);
                tempScore = Int32.Parse(Console.ReadLine());

                if (i == 1)
                {
                    maxScore = tempScore;
                    minScore = tempScore;
                }
                else        // 最大成绩和最小成绩;
                {
                    if (maxScore < tempScore)
                    {
                        maxScore = tempScore;
                    }
                    if (minScore > tempScore)
                    {
                        minScore = tempScore;
                    }
                }

                int temp = tempScore / 10;

                // 统计各区间成绩的人数;
                switch (temp)
                {
                    case 10:
                    case 9:
                        Console.WriteLine("成绩优秀");
                        score90To100++;
                        break;
                    case 8:
                        Console.WriteLine("成绩良好");
                        score80To89++;
                        break;
                    case 7:
                        Console.WriteLine("成绩中等");
                        score70To79++;
                        break;
                    case 6:
                        Console.WriteLine("成绩及格");
                        score60To69++;
                        break;
                    default:
                        Console.WriteLine("成绩不及格");
                        score0To59++;
                        break;
                }
            }

            // 输出统计信息;
            Console.WriteLine("--------学生成绩统计信息输出----------");
            Console.WriteLine("全班共{0:d}人,其中最高成绩{1:f2}," + "最低成绩{2:f2}", nStudents, maxScore, minScore);
            Console.WriteLine("成绩区间90～100的人数有{0:d}人," + "所占比例为:{1:f2}%", score90To100, score90To100 * 100 / nStudents);
            Console.WriteLine("成绩区间80～89的人数有{0:d}人," + "所占比例为:{1:f2}%", score80To89, score80To89 * 100 / nStudents);
            Console.WriteLine("成绩区间70～79的人数有{0:d}人," + "所占比例为:{1:f2}%", score70To79, score70To79 * 100 / nStudents);
            Console.WriteLine("成绩区间60～69的人数有{0:d}人," + "所占比例为:{1:f2}%", score60To69, score60To69 * 100 / nStudents);
            Console.WriteLine("成绩区间0～59的人数有{0:d}人," + "所占比例为:{1:f2}%", score0To59, score0To59 * 100 / nStudents);
            Console.ReadLine();
        }
    }
}
